package com.ag.zlw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbShiftType;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.zlw.service.ShiftTypeService;

/**
 * 班次类型
 * 
 * @author 钟龙伟
 * 
 */

@Scope("prototype")
@Controller("ShiftTypeAction")
public class ShiftTypeAction extends BaseAction {
	private static final long serialVersionUID = -1478025497648926124L;
	@Resource(name = "ShiftTypeService")
	private ShiftTypeService service;
	private List<TbShiftType> shiftTypeList;
	private String message;
	private String psId;
	private String psShift;

	TbShiftType tbShiftType = new TbShiftType();

	public String find() {
		try {
			shiftTypeList = service.findAll();
			System.out.println(shiftTypeList.size());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbShiftType.setPsId(psId);
		try {
			service.delete(tbShiftType);
			this.setMessage("delete success!");
		} catch (Exception e) {
			this.setMessage("delete fail!");
		}
		return "delete_success";
	}

	public String add() {
		tbShiftType.setPsShift(psShift);
		tbShiftType.setA(IDUtil.PRESERVE);
		try {
			service.save(tbShiftType);
			this.setMessage("save success!");
		} catch (Exception e) {
			this.setMessage("save fail!");
		}
		return "add_success";
	}

	public String modify() {
		tbShiftType.setPsId(psId);
		tbShiftType.setPsShift(psShift);
		tbShiftType.setA(IDUtil.PRESERVE);
		try {
			service.modify(tbShiftType);
			this.setMessage("modify success!");
		} catch (Exception e) {
			this.setMessage("modify fail!");
		}
		return "modify_success";
	}

	public List<TbShiftType> getShiftTypeList() {
		return shiftTypeList;
	}

	public void setShiftTypeList(List<TbShiftType> shiftTypeList) {
		this.shiftTypeList = shiftTypeList;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getPsId() {
		return psId;
	}

	public void setPsId(String psId) {
		this.psId = psId;
	}

	public String getPsShift() {
		return psShift;
	}

	public void setPsShift(String psShift) {
		this.psShift = psShift;
	}

}
